//$(document).ready()的简写
$(function () {
    var user=JSON.parse(localStorage.getItem('rootdata')) || [
        { name:'龙龙',root:'高级权限',username:'L020030612',password:'123456',index:0},
        { name:'欣欣',root:'高级权限',username:'Z120070414',password:'123456',index:1},
        { name:'泽泽',root:'普通权限',username:'J020120512',password:'123456',index:2},
        { name:'依依',root:'普通权限',username:'S120070424',password:'123456',index:3},
        { name:'涵涵',root:'普通权限',username:'H120070812',password:'123456',index:4},
        { name:'梅梅',root:'普通权限',username:'M120121012',password:'123456',index:5},
        { name:'佳佳',root:'高级权限',username:'J120041102',password:'123456',index:6},
        { name:'强强',root:'普通权限',username:'Q020051012',password:'123456',index:7},
        { name:'薇薇',root:'普通权限',username:'W120051112',password:'123456',index:8},
        { name:'丽丽',root:'高级权限',username:'L120120320',password:'123456',index:9},
        { name:'茜茜',root:'普通权限',username:'Q120051112',password:'123456',index:10},
        { name:'旭旭',root:'普通权限',username:'X020121218',password:'123456',index:11},
        { name:'倩倩',root:'普通权限',username:'Q120021004',password:'123456',index:12},
        { name:'静静',root:'普通权限',username:'J120070502',password:'123456',index:13},
        { name:'星星',root:'普通权限',username:'X120170210',password:'123456',index:14},
        { name:'维维',root:'高级权限',username:'C020070112',password:'123456',index:15},
        { name:'超超',root:'普通权限',username:'C020050714',password:'123456',index:16},
        { name:'雪雪',root:'高级权限',username:'X120060923',password:'123456',index:17},
        { name:'成成',root:'普通权限',username:'C020050714',password:'123456',index:18},
    ];

    //页面加载获得cookies
    var str3=getCookie('tel');
    var str4=getCookie('pwd');
    var root=[];
    $("input[id='account']").val(str3);
    $("input[id='pass']").val(str4);

    //定义变量
    var oId=false;
    var oJudge=false;
    var oBtn=$('#login');

    // //用户名的正则表达式
    // function isUserName(u){
    //     var reg=/^[A-Z][0|1]20([0|1])[0-9](0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[0|1])$/;
    //     return reg.test(u);
    // }
    //
    // //密码的正则表达式
    // function isPassword(p){
    //     var reg=/^123456$/;
    //     return reg.test(p);
    // }

    //数据库中是否有账号
    function isId() {
        for (i=0;i<user.length;i++){
            if ($("input[id='account']").val()==user[i].username && $("input[id='pass']").val()==user[i].password) {
                oId=true;
                return;
            }else {
                oId=false;
            }
        }
    }

    //点击登录按钮进行验证
    oBtn.click(function () {
        var str1=$("input[id='account']").val();
        var str2=$("input[id='pass']").val();
        var oCheck=$('#remember');
        //判断是否有账号
        isId();
        // 验证用户名
        if (!str1.trim()){
            $('#remind1').css('display','block')
        }else {
            //验证密码
            if (!str2.trim()){
                $('#remind3').css('display','block')
            }else{
                if (oId){
                    oJudge=true;
                } else {
                    $('#remind2').css('display','block')
                }
            }
        }

        //将登陆的账号保存到本地
        function save() {
            for (j=0;j<user.length;j++){
                if (str1 == user[j].username){
                    console.log(user[j]);
                    root.splice(0,1,user[j]);
                    localStorage.setItem('login',JSON.stringify(root));
                    return;
                }
            }
        }

        if (oJudge){
            save();

            if (oCheck.prop("checked")==true){
                setCookie('tel',str1,7);
                setCookie('pwd',str2,7);
            }

            var dep=JSON.parse(localStorage.getItem('部门管理')) || [
                {deptNo:1,dept:'后勤部',office:'w301',tel:13568978998,minister:'',Vice:'',number:''},
                {deptNo:2,dept:'教务部',office:'d203',tel:15568978998,minister:'',Vice:'',number:''},
                {deptNo:3,dept:'行政部',office:'w401',tel:17568978998,minister:'',Vice:'',number:''},
                {deptNo:4,dept:'宣传部',office:'b541',tel:19568978998,minister:'',Vice:'',number:''},
                {deptNo:5,dept:'保卫部',office:'a341',tel:18568978998,minister:'',Vice:'',number:''},
                {deptNo:6,dept:'保育部',office:'e321',tel:13562222998,minister:'',Vice:'',number:''},
                {deptNo:7,dept:'伙食部',office:'e321',tel:13533338998,minister:'',Vice:'',number:''},
            ];
            var arr=JSON.parse(localStorage.getItem('notice')) || [
                {title:"欢迎加入我们",date:"2019-11-16",type:"全体通知",dep:"宣传部",con:"感谢各位家长选择本院，欢迎各位新同学加入本家庭。选择骄阳，选择辉煌！"}
                ];
            var arr1=JSON.parse(localStorage.getItem('grade')) || [
                {name:'音乐',room:'1栋207室',grade:'15大班1班',time:'上午9点'},
                {name:'美术',room:'2栋102室',grade:'16中班2班',time:'下午1点'},
                {name:'故事',room:'3栋101室',grade:'17中班3班',time:'下午3点'},
            ];
            var stu=JSON.parse(localStorage.getItem('stuInform')) ||  [
                {address: "四川省成都市", age: 6, birth: "2013.03.06", callName: "1", callName2: "2", class: "17级大班", date: "2017-09-01", name: "冯宝宝", parent1:"冯慎", parent1_job:"四川省", parent1_tel:"18454967489", parent2:"陈果", parent2_job:"四川省", parent2_tel:"18454967489", photo:"", sex:"女", stu_index:"6"},
                {address: "四川省成都市", age: 6, birth: "2013.05.06", callName: "1", callName2: "2", class: "17级大班", date: "2017-09-01", name: "张楚岚", parent1: "张铁南", parent1_job: "四川省成都市", parent1_tel: "15698784847", parent2: "蔡淑芬", parent2_job: "四川省成都市", parent2_tel: "18469566666", photo: "../images/wwq-img/student-photo.jpg", sex: "男", stu_index: "54"},
                {address: "四川省成都市", age: 4, birth: "2015.06.02", callName: "1", callName2: "2", class: "19级小班", date: "2019-09-01", name: "谭慎", parent1: "谭乏", parent1_job: "四川省成都市", parent1_tel: "15545546555", parent2: "范雨", parent2_job: "四川省成都市", parent2_tel: "13549999999", photo: "../images/wwq-img/student-photo.jpg", sex: "男", stu_index: 55},
                {address: "四川省成都市", age: 5, birth: "2014.03.02", callName: "1", callName2: "2", class: "18级中班", date: "2018-09-01", name: "刘鑫", parent1: "刘明", parent1_job: "四川省成都市", parent1_tel: "17559999999", parent2: "吴倩", parent2_job: "四川省成都市", parent2_tel: "17559999999", photo: "../images/wwq-img/student-photo.jpg", sex: "男", stu_index: 56},
                {address: "四川省成都市", age: 4, birth: "2015.06.01", callName: "1", callName2: "2", class: "19级小班", date: "2019-09-01", name: "夏雨", parent1: "夏东海", parent1_job: "四川省成都市", parent1_tel: "18165454555", parent2: "刘梅", parent2_job: "四川省成都市", parent2_tel: "18165454555", photo: "../images/wwq-img/student-photo.jpg", sex: "男", stu_index: "57"},
                {address: "四川省成都市", age: 6, birth: "2013.01.06", callName: "1", callName2: "2", class: "17级大班", date: "2017-09-01", name: "马丹", parent1: "马魏贤", parent1_job: "四川省成都市", parent1_tel: "15698454555", parent2: "谢春花", parent2_job: "四川省成都市", parent2_tel: "15698454555", photo: "../images/wwq-img/student-photo.jpg", sex: "女", stu_index: "58"},
                {address: "四川省成都市", age: 4, birth: "2015.08.03", callName: "1", callName2: "2", class: "19级小班", date: "2019-09-01", name: "陈茜", parent1: "陈海", parent1_job: "四川省成都市", parent1_tel: "15698777777", parent2: "周冰", parent2_job: "四川省成都市", parent2_tel: "15698777777", photo: "../images/wwq-img/student-photo.jpg", sex: "女", stu_index: 59},
            ];
            var classData=JSON.parse(localStorage.getItem('aClass')) || [
                { orderNumber:'1901', class:'小班', aTeacher:'龙龙', bTeacher:'薇薇', cTeacher:'星星', LifeTeacher:'丽丽', ClassSize:'22', Classroom:'201', SchoolHours:'2019.3', lassDepict:'', index:1,},
                { orderNumber:'1902', class:'小班', aTeacher:'欣欣', bTeacher:'依依', cTeacher:'维维', LifeTeacher:'茜茜', ClassSize:'22', Classroom:'202', SchoolHours:'2019.3', lassDepict:'', index:2,},
                { orderNumber:'1802', class:'中班', aTeacher:'泽泽', bTeacher:'丽丽', cTeacher:'超超', LifeTeacher:'佳佳', ClassSize:'20', Classroom:'101', SchoolHours:'2018.4', lassDepict:'', index:3,},
                { orderNumber:'1805', class:'中班', aTeacher:'涵涵', bTeacher:'茜茜', cTeacher:'雪雪', LifeTeacher:'龙龙', ClassSize:'24', Classroom:'105', SchoolHours:'2018.6', lassDepict:'', index:4,},
                { orderNumber:'1804', class:'中班', aTeacher:'梅梅', bTeacher:'旭旭', cTeacher:'维维', LifeTeacher:'欣欣', ClassSize:'24', Classroom:'106', SchoolHours:'2018.6', lassDepict:'', index:5,},
                { orderNumber:'1702', class:'大班', aTeacher:'佳佳', bTeacher:'倩倩', cTeacher:'依依', LifeTeacher:'涵涵', ClassSize:'22', Classroom:'302', SchoolHours:'2018.6', lassDepict:'', index:6,},
                { orderNumber:'1701', class:'大班', aTeacher:'强强', bTeacher:'静静', cTeacher:'薇薇', LifeTeacher:'静静', ClassSize:'25', Classroom:'301', SchoolHours:'2017.6', lassDepict:'', index:7,},
            ];
            var arri =JSON.parse(localStorage.getItem('teaInform')) || [
                {name:'龙龙',tel:13578901001,isDuty:'yes',sex:'男',bthDay:'1982-01-23',age:25,Job:'L020030612',tcHcu:'无课',oTime:'2003-06-12',dept:'教务部',post:'校长',level:'高级教师',Growth_Archives:'这是一位充满青春热血的校长'},
                {name:'欣欣',tel:13578901002,isDuty:'yes',sex:'女',bthDay:'1990-06-13',age:25,Job:'Z120070414',tcHcu:'幼儿语文',oTime:'2007-04-14',dept:'教务部',post:'部长',level:'高级教师',Growth_Archives:'这是一位细心的老师'},
                {name:'泽泽',tel:13578901003,isDuty:'yes',sex:'男',bthDay:'1983-02-25',age:25,Job:'J020120512',tcHcu:'幼儿数学',oTime:'2012-05-12',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位耐心的老师'},
                {name:'涵涵',tel:13578901004,isDuty:'yes',sex:'女',bthDay:'1995-04-14',age:25,Job:'H120070812',tcHcu:'幼儿故事',oTime:'2007-08-12',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位好看的老师'},
                {name:'梅梅',tel:13578901005,isDuty:'yes',sex:'女',bthDay:'1987-04-05',age:25,Job:'M120121012',tcHcu:'幼儿美术',oTime:'2012-10-12',dept:'教务部',post:'老师',level:'中级教师',Growth_Archives:'这是一位漂亮的老师'},
                {name:'佳佳',tel:13578901021,isDuty:'yes',sex:'女',bthDay:'1992-05-15',age:25,Job:'J120041102',tcHcu:'幼儿品德',oTime:'2004-11-02',dept:'教务部',post:'副部长',level:'高级教师',Growth_Archives:'这是一位认真的老师'},
                {name:'强强',tel:13578901021,isDuty:'yes',sex:'男',bthDay:'1991-07-30',age:25,Job:'Q020051012',tcHcu:'幼儿英语',oTime:'2005-10-12',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位帅气的老师'},
                {name:'薇薇',tel:13578901031,isDuty:'yes',sex:'女',bthDay:'1993-02-20',age:25,Job:'W120051112',tcHcu:'幼儿英语',oTime:'2005-11-12',dept:'教务部',post:'老师',level:'中级教师',Growth_Archives:'这是一位美丽的老师'},
                {name:'依依',tel:13578901041,isDuty:'yes',sex:'女',bthDay:'1990-05-30',age:25,Job:'Y120070424',tcHcu:'幼儿数学',oTime:'2007-04-24',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位用心的老师'},
                {name:'丽丽',tel:13578901051,isDuty:'yes',sex:'女',bthDay:'1992-07-30',age:25,Job:'L120120320',tcHcu:'幼儿早教',oTime:'2012-03-20',dept:'教务部',post:'老师',level:'高级教师',Growth_Archives:'这是一位用心的老师'},
                {name:'茜茜',tel:13578901231,isDuty:'no',sex:'女',bthDay:'1989-06-24',age:25,Job:'Q120051112',tcHcu:'幼儿英语',oTime:'2005-11-12',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位用心的老师'},
                {name:'旭旭',tel:13578901061,isDuty:'no',sex:'男',bthDay:'1988-05-27',age:25,Job:'X020121218',tcHcu:'幼儿体育',oTime:'2012-12-18',dept:'教务部',post:'老师',level:'中级教师',Growth_Archives:'这是一位用心的老师'},
                {name:'倩倩',tel:13578901071,isDuty:'no',sex:'女',bthDay:'1993-11-02',age:25,Job:'Q120021004',tcHcu:'幼儿品德',oTime:'2002-10-04',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位用心的老师'},
                {name:'静静',tel:13578901201,isDuty:'no',sex:'女',bthDay:'1995-04-20',age:25,Job:'J120070502',tcHcu:'幼儿故事',oTime:'2007-05-02',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位用心的老师'},
                {name:'星星',tel:13578901301,isDuty:'no',sex:'女',bthDay:'1989-12-20',age:25,Job:'X120170210',tcHcu:'幼儿英语',oTime:'2017-02-10',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位用心的老师'},
                {name:'维维',tel:13578901401,isDuty:'no',sex:'男',bthDay:'1996-05-28',age:25,Job:'W020040820',tcHcu:'幼儿数学',oTime:'2004-08-20',dept:'教务部',post:'老师',level:'高级教师',Growth_Archives:'这是一位用心的老师'},
                {name:'超超',tel:13578901501,isDuty:'no',sex:'女',bthDay:'1994-02-12',age:25,Job:'C020070112',tcHcu:'幼儿语文',oTime:'2007-01-12',dept:'教务部',post:'老师',level:'中级教师',Growth_Archives:'这是一位用心的老师'},
                {name:'成成',tel:13578901601,isDuty:'no',sex:'男',bthDay:'1995-06-10',age:25,Job:'C020050714',tcHcu:'幼儿品德',oTime:'2005-07-14',dept:'教务部',post:'老师',level:'初级教师',Growth_Archives:'这是一位用心的老师'},
                {name:'雪雪',tel:13578901701,isDuty:'no',sex:'女',bthDay:'1997-05-08',age:25,Job:'X120060923',tcHcu:'幼儿故事',oTime:'2006-09-23',dept:'教务部',post:'老师',level:'高级教师',Growth_Archives:'这是一位用心的老师'},
            ];
            var staff=JSON.parse(localStorage.getItem('员工')) || [
                {dept:'后勤部',name:'张三',position:'部长',tel:1578993214,age:41},
                {dept:'后勤部',name:'张上',position:'副部长',tel:1374493214,age:51},
                {dept:'后勤部',name:'白居易',position:'保洁员',tel:15755521411,age:44},
                {dept:'后勤部',name:'王者荣',position:'保洁员',tel:1874443214,age:29},
                {dept:'后勤部',name:'安妮',position:'保洁员',tel:1576325874,age:51},
                {dept:'后勤部',name:'波塞冬',position:'保洁员',tel:1572580874,age:41},
                {dept:'后勤部',name:'可汗',position:'维修工',tel:1576325874,age:43},
                {dept:'后勤部',name:'小豪',position:'司机',tel:1576334574,age:42},

                {dept:'行政部',name:'王五',position:'部长',tel:17885252423,age:41},
                {dept:'行政部',name:'张伟',position:'副部长',tel:13258963578,age:51},
                {dept:'行政部',name:'张家辉',position:'员工',tel:13232963578,age:33},

                {dept:'保卫部',name:'肖扬',position:'部长',tel:1578993414,age:43},
                {dept:'保卫部',name:'张非',position:'副部长',tel:1374494514,age:31},
                {dept:'保卫部',name:'李白',position:'巡逻',tel:1778912314,age:32},
                {dept:'保卫部',name:'杜甫',position:'保安',tel:1574134574,age:21},

                {dept:'宣传部',name:'阴阳师',position:'部长',tel:1572323414,age:47},
                {dept:'宣传部',name:'洋洋',position:'副部长',tel:1567894514,age:21},
                {dept:'宣传部',name:'白居易',position:'会计',tel:13456794514,age:34},

                {dept:'保育部',name:'芳芳',position:'部长',tel:1572555414,age:37},
                {dept:'保育部',name:'菲菲',position:'副部长',tel:1785894514,age:23},
                {dept:'保育部',name:'咳咳',position:'保育员',tel:1555892214,age:21},
                {dept:'保育部',name:'嘎嘎嘎',position:'保育员',tel:1333894514,age:24},
                {dept:'保育部',name:'烦烦烦',position:'保育员',tel:1543894514,age:27},

                {dept:'伙食部',name:'李世民',position:'部长',tel:1572555414,age:37},
                {dept:'伙食部',name:'月娥',position:'副部长',tel:1785894514,age:23},
                {dept:'伙食部',name:'宙斯',position:'厨师',tel:1576325123,age:31},
                {dept:'伙食部',name:'美杜莎',position:'采购员',tel:1374632584,age:51},
            ];
            var food=JSON.parse(localStorage.getItem('伙食')) || [
                {day1food: "豆花", day2food: "馒头", day3food: "油条", day4food: "麻球", day5food: "豆浆"},
                {day1food: "北京烤鸭", day2food: "宫保鸡丁", day3food: "黄焖鸡", day4food: "鸡公煲", day5food: "宜宾燃面"},
                {day1food: "黑米粥", day2food: "八宝粥", day3food: "大馒头", day4food: "沙拉", day5food: "汉堡"},
            ];
            var memo=JSON.parse(localStorage.getItem('备忘')) || [{txt:'1、整理学院档案；2、规划本周食谱'}];

            localStorage.setItem('部门管理',JSON.stringify(dep));
            localStorage.setItem('notice',JSON.stringify(arr));
            localStorage.setItem('grade',JSON.stringify(arr1));
            localStorage.setItem('stuInform',JSON.stringify(stu));
            localStorage.setItem('stu_index',JSON.stringify(59));
            localStorage.setItem('aClass',JSON.stringify(classData));
            localStorage.setItem('index',JSON.stringify(7));
            localStorage.setItem('teaInform',JSON.stringify(arri));
            localStorage.setItem('备忘',JSON.stringify(memo));
            localStorage.setItem('rootdata',JSON.stringify(user));
            localStorage.setItem('员工',JSON.stringify(staff));
            localStorage.setItem('伙食',JSON.stringify(food));

            $(window).attr('location','home.html');
            // $(location).attr('href', 'http://www.baidu.com');
            // $(location).prop('href', 'http://www.baidu.com')
        }
    });

    //cookies函数
    function setCookie(n,v,i) {
        if (i){
            var oDate=new Date();
            oDate.setDate(oDate.getDate()+i);
            document.cookie=n+'='+v+';path=/;expires='+oDate;
        } else{
            document.cookie=n+'='+v+';path=/;';
        }
    }

    function getCookie(n) {
        var str=document.cookie;
        var arr=str.split('; ');
        for (var i=0;i<arr.length;i++){
            var arr2=arr[i].split('=');
            if (arr2[0]==n){
                return arr2[1];
            }
        }
        return '';
    }

    //用户框获得和失去焦点事件
    $('#account').focus(function () {
        $('.user').css('border-color','#e78713');
        $('#remind1').css('display','none');
        $('#remind2').css('display','none');
    });
    $('#account').focusout(function () {
        $('.user').css('border-color','transparent');
    });

    //密码框获得和失去焦点事件
    $('#pass').focus(function () {
        $('.pwd').css('border-color','#e78713');
        $('#remind3').css('display','none');
        $('#remind2').css('display','none')
    });
    $('#pass').focusout(function () {
        $('.pwd').css('border-color','transparent');
    });

    //关闭提示框事件
    $('.close').click(function () {
        $(this).parent().parent().css('display','none')
    })
});
